//
//  OrderData.m
//
//  Created by   on 2019/2/26
//  Copyright (c) 2019 __MyCompanyName__. All rights reserved.
//

#import "OrderData.h"
#import "OrderGoodsInfo.h"


NSString *const kOrderDataId = @"id";
NSString *const kOrderDataRemakes = @"remakes";
NSString *const kOrderDataUid = @"uid";
NSString *const kOrderDataMoney = @"money";
NSString *const kOrderDataTime = @"time";
NSString *const kOrderDataType = @"type";
NSString *const kOrderDataLostEndTime = @"lost_end_time";
NSString *const kOrderDataGoodsInfo = @"goods_info";
NSString *const kOrderDataNum = @"num";
NSString *const kOrderDataAddrId = @"addr_id";
NSString *const kOrderDataTypeId = @"type_id";
NSString *const kOrderDataJifen = @"jifen";
NSString *const kOrderDataStatus = @"status";


@interface OrderData ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation OrderData

@synthesize dataIdentifier = _dataIdentifier;
@synthesize remakes = _remakes;
@synthesize uid = _uid;
@synthesize money = _money;
@synthesize time = _time;
@synthesize type = _type;
@synthesize lostEndTime = _lostEndTime;
@synthesize goodsInfo = _goodsInfo;
@synthesize num = _num;
@synthesize addrId = _addrId;
@synthesize typeId = _typeId;
@synthesize jifen = _jifen;
@synthesize status = _status;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if (self && [dict isKindOfClass:[NSDictionary class]]) {
            self.dataIdentifier = [self objectOrNilForKey:kOrderDataId fromDictionary:dict];
            self.remakes = [self objectOrNilForKey:kOrderDataRemakes fromDictionary:dict];
            self.uid = [self objectOrNilForKey:kOrderDataUid fromDictionary:dict];
            self.money = [self objectOrNilForKey:kOrderDataMoney fromDictionary:dict];
            self.time = [self objectOrNilForKey:kOrderDataTime fromDictionary:dict];
            self.type = [self objectOrNilForKey:kOrderDataType fromDictionary:dict];
            self.lostEndTime = [self objectOrNilForKey:kOrderDataLostEndTime fromDictionary:dict];
            self.goodsInfo = [OrderGoodsInfo modelObjectWithDictionary:[dict objectForKey:kOrderDataGoodsInfo]];
            self.num = [self objectOrNilForKey:kOrderDataNum fromDictionary:dict];
            self.addrId = [self objectOrNilForKey:kOrderDataAddrId fromDictionary:dict];
            self.typeId = [self objectOrNilForKey:kOrderDataTypeId fromDictionary:dict];
            self.jifen = [self objectOrNilForKey:kOrderDataJifen fromDictionary:dict];
            self.status = [self objectOrNilForKey:kOrderDataStatus fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.dataIdentifier forKey:kOrderDataId];
    [mutableDict setValue:self.remakes forKey:kOrderDataRemakes];
    [mutableDict setValue:self.uid forKey:kOrderDataUid];
    [mutableDict setValue:self.money forKey:kOrderDataMoney];
    [mutableDict setValue:self.time forKey:kOrderDataTime];
    [mutableDict setValue:self.type forKey:kOrderDataType];
    [mutableDict setValue:self.lostEndTime forKey:kOrderDataLostEndTime];
    [mutableDict setValue:[self.goodsInfo dictionaryRepresentation] forKey:kOrderDataGoodsInfo];
    [mutableDict setValue:self.num forKey:kOrderDataNum];
    [mutableDict setValue:self.addrId forKey:kOrderDataAddrId];
    [mutableDict setValue:self.typeId forKey:kOrderDataTypeId];
    [mutableDict setValue:self.jifen forKey:kOrderDataJifen];
    [mutableDict setValue:self.status forKey:kOrderDataStatus];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description  {
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];

    self.dataIdentifier = [aDecoder decodeObjectForKey:kOrderDataId];
    self.remakes = [aDecoder decodeObjectForKey:kOrderDataRemakes];
    self.uid = [aDecoder decodeObjectForKey:kOrderDataUid];
    self.money = [aDecoder decodeObjectForKey:kOrderDataMoney];
    self.time = [aDecoder decodeObjectForKey:kOrderDataTime];
    self.type = [aDecoder decodeObjectForKey:kOrderDataType];
    self.lostEndTime = [aDecoder decodeObjectForKey:kOrderDataLostEndTime];
    self.goodsInfo = [aDecoder decodeObjectForKey:kOrderDataGoodsInfo];
    self.num = [aDecoder decodeObjectForKey:kOrderDataNum];
    self.addrId = [aDecoder decodeObjectForKey:kOrderDataAddrId];
    self.typeId = [aDecoder decodeObjectForKey:kOrderDataTypeId];
    self.jifen = [aDecoder decodeObjectForKey:kOrderDataJifen];
    self.status = [aDecoder decodeObjectForKey:kOrderDataStatus];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_dataIdentifier forKey:kOrderDataId];
    [aCoder encodeObject:_remakes forKey:kOrderDataRemakes];
    [aCoder encodeObject:_uid forKey:kOrderDataUid];
    [aCoder encodeObject:_money forKey:kOrderDataMoney];
    [aCoder encodeObject:_time forKey:kOrderDataTime];
    [aCoder encodeObject:_type forKey:kOrderDataType];
    [aCoder encodeObject:_lostEndTime forKey:kOrderDataLostEndTime];
    [aCoder encodeObject:_goodsInfo forKey:kOrderDataGoodsInfo];
    [aCoder encodeObject:_num forKey:kOrderDataNum];
    [aCoder encodeObject:_addrId forKey:kOrderDataAddrId];
    [aCoder encodeObject:_typeId forKey:kOrderDataTypeId];
    [aCoder encodeObject:_jifen forKey:kOrderDataJifen];
    [aCoder encodeObject:_status forKey:kOrderDataStatus];
}

- (id)copyWithZone:(NSZone *)zone {
    OrderData *copy = [[OrderData alloc] init];
    
    
    
    if (copy) {

        copy.dataIdentifier = [self.dataIdentifier copyWithZone:zone];
        copy.remakes = [self.remakes copyWithZone:zone];
        copy.uid = [self.uid copyWithZone:zone];
        copy.money = [self.money copyWithZone:zone];
        copy.time = [self.time copyWithZone:zone];
        copy.type = [self.type copyWithZone:zone];
        copy.lostEndTime = [self.lostEndTime copyWithZone:zone];
        copy.goodsInfo = [self.goodsInfo copyWithZone:zone];
        copy.num = [self.num copyWithZone:zone];
        copy.addrId = [self.addrId copyWithZone:zone];
        copy.typeId = [self.typeId copyWithZone:zone];
        copy.jifen = [self.jifen copyWithZone:zone];
        copy.status = [self.status copyWithZone:zone];
    }
    
    return copy;
}


@end
